package com.oliver.aicoder.config.mvc;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;

public class MvcStringJsonDeserializer extends JsonDeserializer<String> {

    @Override
    public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
        String text = p.getText(); // 获取 JSON 字符串
        if (text == null || text.trim().isEmpty()) {
            return null; // 去掉前后空格后为空字符串或 null，则返回 null
        }
        return text.trim(); // 返回去空格后的字符串
    }
}